<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="Content-Language" content="zh-CN"><link href="stylesheet.css" media="all" rel="stylesheet" type="text/css">
<title>CREATE CONSTRAINT TRIGGER</title>
<script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?d286c55b63a3c54a1e43d10d4c203e75"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script>
</head><body class="REFENTRY">
<div>
<table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><th colspan="5" align="center" valign="bottom">PostgreSQL 8.2.3 中文文档</th></tr>
<tr><td width="10%" align="left" valign="top"><a href="sql-createcast.html" accesskey="P">后退</a></td><td width="10%" align="left" valign="top"><a href="sql-createcast.html">快退</a></td><td width="60%" align="center" valign="bottom"></td><td width="10%" align="right" valign="top"><a href="sql-createconversion.html">快进</a></td><td width="10%" align="right" valign="top"><a href="sql-createconversion.html" accesskey="N">前进</a></td></tr>
</table>
<hr align="LEFT" width="100%"></div>
<h1><a name="SQL-CREATECONSTRAINT"></a>CREATE CONSTRAINT TRIGGER</h1>
<div class="REFNAMEDIV"><a name="AEN46767"></a><h2>名称</h2>CREATE CONSTRAINT TRIGGER&nbsp;--&nbsp;定义一个新的约束触发器</div>
<a name="AEN46770"></a>
<div class="REFSYNOPSISDIV"><a name="AEN46772"></a><h2>语法</h2>
<pre class="SYNOPSIS">CREATE CONSTRAINT TRIGGER <tt class="REPLACEABLE"><i>name</i></tt>
    AFTER <tt class="REPLACEABLE"><i>event [ OR ... ]</i></tt>
    ON <tt class="REPLACEABLE"><i>table_name</i></tt>
    [ FROM <tt class="REPLACEABLE"><i>referenced_table_name</i></tt> ]
    { NOT DEFERRABLE | [ DEFERRABLE ] { INITIALLY IMMEDIATE | INITIALLY DEFERRED } }
    FOR EACH ROW
    EXECUTE PROCEDURE <tt class="REPLACEABLE"><i>funcname</i></tt> ( <tt class="REPLACEABLE"><i>arguments</i></tt> )</pre>
</div>
<div class="REFSECT1"><a name="AEN46780"></a><h2>描述</h2>
<p><tt class="COMMAND">CREATE CONSTRAINT TRIGGER</tt> 被 <tt class="COMMAND">CREATE TABLE</tt>/<tt class="COMMAND">ALTER TABLE</tt> 内部使用以及被 <span class="APPLICATION">pg_dump</span> 用于创建那些用于参照完整性的特殊触发器。它并不是为了普通使用而设计的。</p>
</div>
<div class="REFSECT1"><a name="AEN46787"></a><h2>参数</h2>
<div class="VARIABLELIST">
<dl>
<dt><tt class="REPLACEABLE"><i>name</i></tt></dt>
<dd><p>约束触发器的名称。实际创建的触发器名字将是 <tt class="LITERAL">RI_ConstraintTrigger_0000</tt> 格式(这里的 0000 是服务器指定的某个数字)。在删除触发器的时候必须使用这个名字。</p></dd>
<dt><tt class="REPLACEABLE"><i>event</i></tt></dt>
<dd><p>触发该触发器的事件。是 <tt class="LITERAL">INSERT</tt>, <tt class="LITERAL">UPDATE</tt>, <tt class="LITERAL">DELETE</tt> 之一，可以使用 <tt class="LITERAL">OR</tt> 指定多个值。</p></dd>
<dt><tt class="REPLACEABLE"><i>table_name</i></tt></dt>
<dd><p>发生触发器事件的表名称(可能有模式修饰)</p></dd>
<dt><tt class="REPLACEABLE"><i>referenced_table_name</i></tt></dt>
<dd><p>被约束引用的表名称(可能有模式修饰)。外键约束触发器要使用它。</p></dd>
<dt><tt class="LITERAL">DEFERRABLE</tt><br><tt class="LITERAL">NOT DEFERRABLE</tt><br><tt class="LITERAL">INITIALLY IMMEDIATE</tt><br><tt class="LITERAL">INITIALLY DEFERRED</tt></dt>
<dd><p>参见 <a href="sql-createtable.html"><i>CREATE TABLE</i></a> 文档以获取这些约束选项的细节。</p></dd>
<dt><tt class="REPLACEABLE"><i>funcname</i></tt>(<tt class="REPLACEABLE"><i>args</i></tt>)</dt>
<dd><p>触发器处理过程中调用的函数。参见 <a href="sql-createtrigger.html"><i>CREATE TRIGGER</i></a> 获取细节。</p></dd>
</dl>
</div>
</div>
<div class="REFSECT1"><a name="AEN46834"></a><h2>兼容性</h2>
<p><tt class="COMMAND">CREATE CONTRAINT TRIGGER</tt> 是 PostgreSQL 在 SQL 标准基础上的扩展。</p>
</div>
<div>
<hr align="LEFT" width="100%">
<table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td width="33%" align="left" valign="top"><a href="sql-createcast.html" accesskey="P">后退</a></td><td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">首页</a></td><td width="33%" align="right" valign="top"><a href="sql-createconversion.html" accesskey="N">前进</a></td></tr>
<tr><td width="33%" align="left" valign="top">CREATE CAST</td><td width="34%" align="center" valign="top"><a href="sql-commands.html" accesskey="U">上一级</a></td><td width="33%" align="right" valign="top">CREATE CONVERSION</td></tr>
</table>
</div>
</body></html>